import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/home/Home'
import Login from '@/components/Login'
import FileList from '@/components/FileList'
import FileUpload from '@/components/FileUpload'
import UserManagen from '@/components/UserManagen'
import store from '../store'
import { Message } from "element-ui";



Vue.use(Router)
export const asyncRoutes = [
    {
        path: '/',
        name: '登录',
        hidden: true,
        component: Login
    },
    // {
    //     path: '/home',
    //     name: '部门发文',
    //     component: Home,
    //     iconCls: 'el-icon-folder',
    //     meta: {
    //         requireAuth: true
    //     },
    //     children: [
    //         {
    //             path: '/fileList',
    //             name: '文档列表',
    //             component: FileList,
    //             meta: {
    //                 keepAlive: true,
    //                 requireAuth: true
    //             }
    //         },
    //         {
    //             path: '/fileUpload',
    //             name: '上传文档',
    //             component: FileUpload,
    //             meta: {
    //                 keepAlive: false,
    //                 requireAuth: true
    //             }
    //         }
    //     ]
    // },
    // 产品策划信息板块
    {
        path: '/home',
        name: '产品策划',
        iconCls: 'el-icon-s-marketing',
        component: Home,
        redirect: '/planning_list',
        meta: {
            requireAuth: true,
            breadcrumb: '产品策划'
        },
        children: [
            {
                path: '/planning_list',
                name: '策划列表',
                component: (resolve) => require(["@/views/planList/PlanList"], resolve),
                meta: {
                    requireAuth: true,
                    keepAlive: true,
                    breadcrumb: '策划列表',
                }
            },
            {
                path: "/planning_edit/:id",
                hidden: true,
                name: '策划编辑',
                meta: {
                    title: "策划编辑",
                    requireAuth: true,
                    breadcrumb: '策划编辑',
                    office: ["18"]
                },
                component: (resolve) => require(['@/views/planForm/PlanEdit'], resolve),
                // beforeEnter: (to, from, next) => {
                //     console.log("路由守卫");
                //     console.log(to.params.id);
                //   },
            },
            {
                path: '/planning_create',
                name: '新建策划',
                meta: {
                    requireAuth: true,
                    breadcrumb: '新建策划',
                    office: "18",
                },
                component: (resolve) => require(['@/views/planForm/PlanCreate'], resolve),
                beforeEnter: (to, from, next) => {
                    console.log("路由守卫")
                    if (store.state.loginUser.data.office == "18") {
                        next();
                    } else {
                        console.log(Message.warning("只有产品策划室可以创建产品策划"));
                    }
                }
            },
            {
                path: "/planning_detail/:id",
                hidden: true,
                name: '策划详情',
                meta: {
                    title: "策划详情",
                    breadcrumb: '策划详情',
                    requireAuth: true,
                },
                component: (resolve) => require(['@/views/planDetail/PlanDetail'], resolve),

            },
            // {
            //     path: '/brand_list',
            //     name: '品牌列表',
            //     meta: {
            //         requireAuth: true,
            //         breadcrumb: '品牌列表',
            //         office: ["99"],
            //     },
            //     component: (resolve) => require(['@/components/Planning/brand/index.vue'], resolve)
            // },
            {
                path: '/distribution_channel_list',
                name: '销售渠道',

                meta: {
                    requireAuth: true,
                    breadcrumb: '销售渠道',
                    office: ["18"]
                },
                component: (resolve) => require(['@/components/Planning/distribution_channel_list/index.vue'], resolve)
            }

        ]
    },
    // 个人工作台板块
    {
        path: '/home',
        name: '工作台',
        component: Home,
        meta: {
            requireAuth: true,
            breadcrumb: '工作台',
            keepAlive: true,
            office: ["18"]
        },
        children: [
            {
                path: '/workbeach',
                iconCls: 'el-icon-house',
                name: '工作台',
                meta: {
                    requireAuth: true,
                    breadcrumb: '工作台',
                    keepAlive: true,
                    office: ["18"]
                },
                component: (resolve) => require(['@/views/WorkBeach/index'], resolve)
            }
        ],
    },
    // 管理员入口
    {
        path: '/home',
        name: '用户管理',
        component: Home,
        iconCls: 'el-icon-user',
        meta: {
            requireAuth: true,
            breadcrumb: '用户管理',
            roles: ["超级管理员"]
        },
        children: [
            {
                path: '/user',
                name: '原用户管理',
                component: UserManagen,
                meta: {
                    requireAuth: true,
                    roles: ["超级管理员"],
                    breadcrumb: '用户管理'
                }
            },
            {
                path: '/UserList',
                name: '现用户管理',
                component: (resolve) => require(['@/views/UserManager/UserList'], resolve),
                meta: {
                    requireAuth: true,
                    roles: ["超级管理员"],
                    breadcrumb: '用户管理'
                }
            }
        ],
    },
    { path: '*', redirect: '/403', hidden: true }

]



export const constantRouterMap = [
    {
        path: '/', component: Login, hidden: true, name: "登录"
    },
    {
        name: "403",
        path: '/403',
        hidden: true,
        component: () => import('@/views/NotFound')
    },
    {
        path: '/home',
        name: '部门发文',
        component: Home,
        iconCls: 'el-icon-folder',
        meta: {
            requireAuth: true
        },
        children: [
            {
                path: '/fileList',
                name: '文档列表',
                component: FileList,
                meta: {
                    keepAlive: true,
                    requireAuth: true
                }
            },
            {
                path: '/fileUpload',
                name: '上传文档',
                component: FileUpload,
                meta: {
                    keepAlive: false,
                    requireAuth: true
                }
            }
        ]
    },
    // 产品策划信息板块
    {
        path: '/home',
        name: '产品策划',
        iconCls: 'el-icon-s-marketing',
        component: Home,
        redirect: '/planning_list',
        meta: {
            requireAuth: true,
            breadcrumb: '产品策划'
        },
        children: [
            {
                path: '/planning_list',
                name: '策划列表',
                component: () => import("@/views/planList/PlanList"),
                meta: {
                    requireAuth: true,
                    keepAlive: true,
                    breadcrumb: '策划列表',
                }
            },
            {
                path: "/planning_detail/:id",
                hidden: true,
                name: '策划详情',
                meta: {
                    title: "策划详情",
                    breadcrumb: '策划详情',
                    requireAuth: true,
                },
                component: () => import("@/views/planDetail/PlanDetail")
            },
        ]
    },
    { path: '*', redirect: '/403', hidden: true }

]
// 路由拦截

// export const  asyncRoutes = [
//     {
//         path: '/home',
//         name: '产品策划',
//         iconCls: 'el-icon-s-marketing',
//         component: Home,
//         redirect: '/planning_list',
//         meta: {
//             requireAuth: true,
//             breadcrumb: '产品策划'
//         },
//         children: [
//             {
//                 path: "/planning_edit/:id",
//                 hidden: true,
//                 name: '策划编辑',
//                 meta: {
//                     title: "策划编辑",
//                     roles: ['普通员工', '科室主任'],
//                     office: ['7',],
//                     breadcrumb: '策划编辑'
//                 },
//                 component: (resolve) => require(['../components/Planning/edit/index.vue'], resolve)
//             },
//             {
//                 path: '/planning_create',
//                 name: '新建策划',
//                 meta: {
//                     requireAuth: true,
//                     breadcrumb: '新建策划',
//                     office: "7",
//                 },
//                 component: (resolve) => require(['../components/Planning/add/index.vue'], resolve),

//             },
//             {
//                 path: "/planning_detail/:id",
//                 hidden: true,
//                 name: '策划详情',
//                 meta: {
//                     title: "策划详情",
//                     breadcrumb: '策划详情'
//                 },
//                 component: (resolve) => require(['../components/Planning/detail/index.vue'], resolve)
//             },
//             {
//                 path: '/brand_list',
//                 name: '品牌列表',
//                 meta: {
//                     requireAuth: true,
//                     breadcrumb: '品牌列表'
//                 },
//                 component: (resolve) => require(['../components/Planning/brand/index.vue'], resolve)
//             },
//             {
//                 path: '/distribution_channel_list',
//                 name: '销售渠道',

//                 meta: {
//                     requireAuth: true,
//                     breadcrumb: '销售渠道'
//                 },
//                 component: (resolve) => require(['../components/Planning/distribution_channel_list/index.vue'], resolve)
//             }

//         ]
//     },
//     {
//         path: '/home',
//         name: '工作台',
//         component: Home,
//         redirect: '/planning_list',
//         meta: {
//             requireAuth: true,
//             breadcrumb: '工作台',
//             keepAlive: true,
//             office: ["7"],
//         },
//         children: [
//             {
//                 path: '/workbeach',
//                 iconCls: 'el-icon-house',
//                 name: '我的工作台',
//                 meta: {
//                     requireAuth: true,
//                     breadcrumb: '工作台',
//                     keepAlive: true,
//                     office: ["7"]
//                 },
//                 component: () => import("@/views/workBeach/index")
//             }
//         ]
//     },
//     {
//         path: '/home',
//         name: '首页',
//         component: Home,
//         iconCls: 'el-icon-user',
//         meta: {
//             requireAuth: true,
//             breadcrumb: '首页',
//             roles: ["超级管理员"]
//         },
//         children: [
//             {
//                 path: '/user',
//                 name: '用户管理',
//                 component: UserManagen,
//                 meta: {
//                     requireAuth: true,
//                     roles: ["超级管理员"],
//                     breadcrumb: '用户管理'
//                 }
//             },
//             {
//                 path: '/UserList',
//                 name: '用户管理',
//                 component: (resolve) => require(['../components/UserManager/UserList.vue'], resolve),
//                 meta: {
//                     requireAuth: true,
//                     roles: ["超级管理员"],
//                     breadcrumb: '用户管理'
//                 }
//             }
//         ],
//     },
//     { path: '*', redirect: '/404', hidden: true }
// ]
/**
 * 重写路由的push方法
 */
//  const routerPush = Router.prototype.push
//  Router.prototype.push = function push(location) {
//      return routerPush.call(this, location).catch(err => err)
//  }
const createRouter = () => new Router({
    // mode: 'history',
    routes: constantRouterMap
})
const router = createRouter()
export default router

